package org.example.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.example.system.entity.Concern;
import org.example.system.entity.Post;
import org.example.system.entity.User;
import org.example.system.mapper.ConcernMapper;
import org.example.system.service.ConcernService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;

/**
 * 关注实现类
 */
@Service
public class ConcernServiceImpl implements ConcernService {
    @Autowired
    private ConcernMapper concernMapper;

    /**
     * 按条件分页查询
     * @param concern
     * @return
     */
    @Override
    public IPage<Concern> selectPage(Concern concern){
        LambdaQueryWrapper<Concern> wrapper = new LambdaQueryWrapper<>();
        if (concern.getUserId() != null){
            wrapper.eq(Concern::getUserId,concern.getUserId());
        }
        if (concern.getConcernUserId() != null){
            wrapper.eq(Concern::getConcernUserId,concern.getConcernUserId());
        }
        IPage<Concern> page = new Page<>();
        page.setCurrent(concern.getPageNum());
        page.setSize(concern.getPageSize());
        return concernMapper.selectPage(page,wrapper);
    }
    
    /**
     * 添加帖子
     * @param concern
     * @return
     */
    @Override
    public int add(Concern concern) {
        concern.setUpdateTime(new Date());
        concern.setNote("关注创建成功！");
        return concernMapper.insert(concern);
    }
    /**
     * 删除
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(Long[] ids) {
        return concernMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 根据id获取信息
     * @param id
     * @return
     */
    @Override
    public Concern getOne(Long id) {
        return concernMapper.selectById(id);
    }
}
